package ArrayTest.Homework.HotelTest;

public class Hotel {
    private Room[][] rooms;

    {
        //初始化酒店房间
        rooms = new Room[5][10];
        for(int i = 0; i < rooms.length; i++){
            for(int j = 0; j < rooms[i].length; j++){
                rooms[i][j] = new Room();
                rooms[i][j].setNum((i+1) * 100 + (j+1));
                rooms[i][j].setFlag(true);
                if(i == 0){
                    rooms[i][j].setType("单人间");
                }else if(i == 1){
                    rooms[i][j].setType("双人间");
                }else if(i == 2){
                    rooms[i][j].setType("豪华包间");
                }else if(i == 3){
                    rooms[i][j].setType("电竞包间");
                }else{
                    rooms[i][j].setType("总统套房");
                }
            }
        }
    }

    //预定房间
    public void reserveRoom(int num){
        int i = (num / 100) - 1;  //取出num中的第一位数
        int j = (num % 100) - 1;  //取出num中的后两位数
        if(rooms[i][j].isFlag()){     //判断房间是否空闲
            rooms[i][j].setFlag(false);
            System.out.println("预定成功，您的房间编号为"+num+" 类型为"+rooms[i][j].getType());
        }else{
            System.out.println("预定失败，房间已有住户，请选泽其他空闲房间。");
        }
    }
    //退订房间
    public void unregRoom(int num){
        int i = (num / 100) - 1;  //取出num中的第一位数
        int j = (num % 100) - 1;  //取出num中的后两位数
        if(!(rooms[i][j].isFlag())){  //判断房间是否空闲
            rooms[i][j].setFlag(true);
            System.out.println("退订成功，退订房间编号为"+num+" 类型为"+rooms[i][j].getType());
        }else{
            System.out.println("退订失败，房间无住户，可以入住。");
        }
    }

    //打印所有房间信息
    public void printRoom(){
        for(int i = 0; i < rooms.length; i++){
            for(int j = 0; j < rooms[i].length; j++){
                System.out.print(rooms[i][j]);
            }
            System.out.println();
        }
    }
}
